﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class ProcedureTypeElement : SyntaxTreeElement, ITypeElement
    {
        protected TokenInfo type;
        protected List<FunctionVarDeclarationElement> vars;
        protected bool ofobject;
        protected List<DirectiveElement> directives;

        public TokenInfo Type { get { return type; } set { type = value; } }
        public List<FunctionVarDeclarationElement> Vars { get { return vars; } set { vars = value; } }
        public bool OfObject { get { return ofobject; } set { ofobject = value; } }
        public List<DirectiveElement> Directives { get { return directives; } set { directives = value; } }

        public ProcedureTypeElement(TokenInfo Type, List<FunctionVarDeclarationElement> Vars, bool OfObject, List<DirectiveElement> Directives, List<TokenInfo> Comments)
            : base(Type, Comments)
        {
            type = Type;
            vars = Vars;
            ofobject = OfObject;
            directives = Directives;
        }

        public override string ToString()
        {
            string result = type.Text;
            if((vars!=null)&&(vars.Count>0))
                result+=string.Format("({0})", vars.Join("; "));
            if (ofobject)
                result += " of object";
            if ((directives != null) && (directives.Count > 0))
                result += string.Format("; {0}", directives.Join("; "));
            return result;
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (vars != null)
                foreach (FunctionVarDeclarationElement var in vars)
                    yield return var;
            if (directives != null)
                foreach (DirectiveElement directive in directives)
                    yield return directive;
        }
    }
}
